<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link href="../css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="../css/setting.css" />
</head>
<body class="gray">
	<div class="mui-content merchant loading" id="vueMain"> 
	    <div class="title">基本信息</div>
	    <form class="mui-input-group">
	        <div class="mui-input-row">
	            <label>您的称呼：</label>
	            <input type="text" v-model="req.name" class="mui-input-clear" placeholder="">
	        </div>
	        <div class="mui-input-row">
	            <label>公司称呼：</label>
	            <input type="text" v-model="req.shop_name" class="mui-input-clear" placeholder="">
	        </div>
	        <div class="mui-input-row">
	            <label>联系方式：</label>
	            <input type="number" v-model="req.mobile" class="mui-input-clear" placeholder="">
	        </div>
	        <div class="mui-input-row getcode">
	        	 	<label>验证码：</label>
	            <input type="number" v-model="req.code" placeholder="" />
	            <a class="mui-btn bexta-btn bexta-btn-red code">获取验证码</a>
	        </div>
	        <div class="mui-input-row getType">
	            <label>供应方向：</label>
	            <div class="sa">{{name}}</div>
	        </div>
	    </form>
	    <p style="text-align: center;padding:25px 0px">提交后，客服人员会与您取得联系</p>
	    
	    <div class="mui-content-padded" style="margin-top: 25px;">
			<button type="button" class="mui-btn bexta-btn bexta-btn-red mui-btn-block enter">提交</button>
	    </div>
	</div>
<script src="../js/mui.js"></script>
<script src="../js/vue.min.js"></script>
<script src="../js/bexta.js"></script>
<script type="text/javascript">
	var apps, views;
	mui.init()
	mui.plusReady(function () {
	   bexta.ajax(api.site, function(res){
	   		initVue(res);
	   }, {});
	});
	function initVue(res){
		apps = new Vue({
			el:'#vueMain',
			data:{
				list:res,
				typeid:[],
				name:'',
				req:{
					name:'',
					shop_name:'',
					mobile:'',
					code:'',
					commend_id:''
				}
			},
			mounted:function(){
				document.querySelector('.loading').classList.add('loadRun');
				var self = this;
				mui('#vueMain').on('tap', '.code', function(){
					if( check.phone(apps.req.mobile) ){
						var f = mui('.code').button('loading');
						bexta.ajax(''+api.send_msg, function(res){
							if( res.isError == 0 ){
								mui.toast(res.msg);
								bexta.countDown(90, function(m){
									if( m <=1  ){
										f.reset();
									}else{
										f.setText(m + '秒');
									}
								});
							}
						},{data:{uid:bexta.getStorage(USER).uid,mobile:apps.req.mobile,type:5}},function(){
							f.reset();
						});
						
					}else{
						mui.toast('手机号有误');
					}
				});
				mui('#vueMain').on('tap', '.getType', function(){
					bexta.openWithTitle({
						id:'occupation',
						url:'../center/occupation.html',
						extras:{
							val:apps.list.classes,
							def:apps.typeid
						}
					})
				});
				//提交
				mui('#vueMain').on('tap', '.enter', function(){
					if( self.req.name == '' ){
						mui.toast('请输入大名');
						return;
					}
					if( self.req.shop_name == '' ){
						mui.toast("请输入公司名");
						return;
					}
					if( !check.phone(self.req.mobile) ){
						mui.toast("手机号码有误");
						return ;
					}
					if( self.req.code == '' ){
						mui.toast("验证码错误");
						return;
					}
					if( self.typeid.length  < 1 ){
						mui.toast("请选择供应方向");
						return ;
					}
					
					var send = self.req;
					send.commend_id = self. typeid.join(',');
					bexta.ajax(api.add_shop, function(res,msg){
						mui.toast(msg);
						if(!res){
							mui.later(function(){
								this.back();
							},500,mui)
						}
					},{data:send});
					
					
				});
			}
		});
	}
window.addEventListener('callVal', function(evt){
	var v = evt.detail.val;
	apps.typeid = v;
	apps.name = '';
	mui.each( apps.list.classes, function(){
		for( var index = 0; index < v.length; index++ ){
			if( this.id == v[index] ){
				apps.name +=this.name + " ";
			}
		}
	} );
});
</script>
</body>
</html>